import { EggAppConfig, EggAppInfo, PowerPartial } from "egg";

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1626680094829_5457";
  // 配置需要的中间件，数组顺序即为中间件的加载顺序

  // add your egg config in here
  config.middleware = ["response","mystatic"];
  // slow 中间件的 options 参数
  config.mystatic = {
    path: "view",
  };
  config.multipart = {
    fileExtensions: ["txt",'vue','md'],
  };

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };
  // 关闭csrf开关的工具
  config.security = {
    csrf: {
      enable: false,
    },
  };
  config.mongoose = {
    client: {
      url: "mongodb://127.0.0.1/example",
      options: {},
    },
  };
  config.mysql = {
    client: {
      host: "localhost",
      port: "3306",
      user: "root",
      password: "root",
      database: "cms",
    },
  };

  config.view = {
    defaultExtension: ".html",
    defaultViewEngine: "nunjucks",
    mapping: {
      ".nj": "nunjucks",
      ".hbs": "handlebars",
      ".ejs": "ejs",
      ".js": "assets",
    },
  };
  // config.sequelize = {
  //   dialect: "mysql",
  //   host: "127.0.0.1",
  //   port: 3306,
  //   username: "root",
  //   password: "",
  //   database: "example",
  //   delegate: "sqlModel", //定义挂载到框架上为ctx.sqlModel
  //   baseDir: "sqlModel", //定义model文件目录app/`${sqlModel}
  // };

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
